package com.wfm.leetcode.editor.cn;

/**
 * 时间复杂度：mnC^2   C是过滤器的宽高
 * 空间复杂度：1  返回值不计算空间复杂度
 */
public class PSix61图片平滑器{
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int[][] imageSmoother(int[][] img) {
        int m = img.length;
        int n = img[0].length;
        int[][] res = new int[m][n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                int num=0,sum=0;
                for (int k = i-1; k <= i+1; k++) {
                    for (int l = j-1; l <=j+1 ; l++) {
                        if(k>=0&&k<m&&l>=0&&l<n){
                            num++;
                            sum+=img[k][l];
                        }
                    }
                }
                res[i][j]=sum/num;
            }
        }
        return res;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

    public static void main(String[] args) { 
        Solution solution = new PSix61图片平滑器().new Solution();
    }
}